home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 December: Technology Seed / ATS Dec. '97.toast / Navigation Services SDK 1.0b1 / Examples / Sampler / Sampler ƒ / Template.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  3.9 KB  |  179 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Template.c
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment AppSeg
  9.  
  10. #ifndef __GESTALT__
  11. #include <Gestalt.h>
  12. #endif
  13.  
  14. #ifndef Common_Defs
  15. #include "Common.h"
  16. #endif
  17.  
  18. short        gQuit, gQuitting;
  19. short        gDocumentCount;
  20. Document*    gDocumentList[kMaxDocumentCount];
  21. short        gFontItem, gSizeItem;
  22. short        gInBackground;
  23. Document*    gFrontDocument;
  24. short        gCanUndoDrag;
  25. WindowPtr    gUndoFrontmost, gLastFrontmost;
  26. Boolean        gCanDrag;
  27. Boolean        gCanPrint;
  28. THPrint        gPrintRecord;
  29. Boolean        gNavServicesExists;
  30.  
  31. // AppleEvent handlers:
  32. AEEventHandlerUPP    myODOCEventHandler;
  33. AEEventHandlerUPP    myQAPPEventHandler;
  34. AEEventHandlerUPP    myOAPPEventHandler;
  35. ControlActionUPP     myActionProcUPP;
  36.  
  37. // for MixedMode:
  38. #ifndef NewEventHandlerProc
  39.     #define NewEventHandlerProc(x) (EventHandlerProcPtr)x
  40. #endif
  41.  
  42. // prototypes:
  43. void InitializeToolbox(void);
  44. void InitializeGlobals(void);
  45. void SetupMenus(void);
  46. void InstallEventHandlers(void);
  47.  
  48.  
  49. // *****************************************************************************
  50. // *
  51. // *    InitializeToolbox()
  52. // *
  53. // *****************************************************************************
  54. void InitializeToolbox()
  55. {    
  56.     long result = 0;
  57.  
  58.     InitGraf(&qd.thePort);
  59.     InitFonts();
  60.     InitWindows();
  61.     InitMenus();
  62.     TEInit();
  63.     InitDialogs(0L);
  64.     InitCursor();
  65.  
  66.     MoreMasters();
  67.     MoreMasters();
  68.     MaxApplZone();
  69.  
  70.     FlushEvents(everyEvent,0);
  71. }
  72.  
  73.  
  74. // *****************************************************************************
  75. // *
  76. // *    InitializeGlobals()
  77. // *
  78. // *****************************************************************************
  79. void InitializeGlobals()
  80. {    
  81.     long result = 0;
  82.  
  83.     gQuit             = gQuitting = false;
  84.     gDocumentCount     = 0;
  85.     gFontItem         = gSizeItem = 0;
  86.     gInBackground     = false;
  87.     gCanUndoDrag     = slCantUndo;
  88.     gPrintRecord    = nil;
  89.  
  90.     if ((Gestalt(gestaltDragMgrAttr,&result) != noErr) || (!(result & (1 << gestaltDragMgrPresent))))
  91.         gCanDrag = false;
  92.     else
  93.         gCanDrag = true;
  94.  
  95.     gCanPrint = false;
  96.  
  97.     // Check for Navigation Services 
  98.     gNavServicesExists = NavServicesAvailable();
  99. }
  100.  
  101.  
  102. // *****************************************************************************
  103. // *
  104. // *    SetupMenus()
  105. // *
  106. // *****************************************************************************
  107. void SetupMenus()
  108. {    
  109.     Handle        theMenuBar;
  110.     Str255        theStr;
  111.  
  112.     theMenuBar = GetNewMBar(MenuBarID);
  113.  
  114.     SetMenuBar(theMenuBar);
  115.     DisposeHandle(theMenuBar);
  116.  
  117.     AppendResMenu(GetMenuHandle(idAppleMenu),'DRVR');
  118.  
  119.     GetIndString(theStr,MenuStringsID,slCantUndo);
  120.     SetMenuItemText(GetMenuHandle(idEditMenu),iUndo,theStr);
  121.  
  122.     DrawMenuBar();
  123. }
  124.  
  125.  
  126. // *****************************************************************************
  127. // *
  128. // *    InstallEventHandlers()
  129. // *
  130. // *****************************************************************************
  131. void InstallEventHandlers()
  132. {
  133.     long     result = 0;
  134.     OSErr     theErr = noErr;
  135.     
  136.     theErr = Gestalt(gestaltAppleEventsAttr,&result);
  137.     if (theErr == noErr)
  138.         {
  139.         myODOCEventHandler = NewAEEventHandlerProc(MyHandleODOC);
  140.         myQAPPEventHandler = NewAEEventHandlerProc(MyHandleQUIT);
  141.         myOAPPEventHandler = NewAEEventHandlerProc(MyHandleOAPP);
  142.  
  143.         (void)AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,myOAPPEventHandler,0,false);    
  144.         (void)AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,myQAPPEventHandler,0,false);
  145.         (void)AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,myODOCEventHandler,0,false);
  146.         }
  147. }
  148.  
  149.  
  150. // *****************************************************************************
  151. main()
  152. {
  153.     long result = 0;
  154.     OSErr theErr = noErr;
  155.     
  156.     InitializeToolbox();
  157.     InitializeGlobals();
  158.     InstallEventHandlers();
  159.     SetupMenus();
  160.     
  161.     myActionProcUPP = NewControlActionProc(ScrollProc);
  162.  
  163.     AdjustMenus();
  164.  
  165.     EventLoop();
  166.  
  167.     theErr = Gestalt(gestaltAppleEventsAttr,&result);
  168.     if (theErr != noErr)
  169.         {
  170.         DisposeRoutineDescriptor(myODOCEventHandler);
  171.         DisposeRoutineDescriptor(myQAPPEventHandler);
  172.         DisposeRoutineDescriptor(myOAPPEventHandler);
  173.         }
  174.  
  175.     DisposeRoutineDescriptor(myActionProcUPP);
  176.  
  177.     return 0;
  178. }
  179.